package com.eastcom.bm.service.impl;


import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;

import com.eastcom.bm.atom.Atom_PublicNe;
import com.eastcom.bm.atom.DataAbnormal;
import com.eastcom.bm.atom.RawData;
import com.eastcom.bm.dao.DAOFactory;
import com.eastcom.bm.dao.IPublicNeDao;
import com.eastcom.bm.dataprocess.processor.ModelInfo;
import com.eastcom.bm.service.IPublicNeService;
import com.eastcom.bm.service.ServiceFactory;
import com.eastcom.common.db.DataSourceFactory;
import com.eastcom.common.db.JDBCTemplate;
import com.eastcom.common.util.CharliDate;
import com.eastcom.providor.BMSetting;


public class PublicNeService implements IPublicNeService {

	private static Logger log = BMSetting.getBMlog();

	public List<Atom_PublicNe> getAllPublicNe() {
		// TODO Auto-generated method stub
		try{
			IPublicNeDao publicNeDao=DAOFactory.getInstance().getPublicNeDao();
			return publicNeDao.getAllPublicNe();
		}
		catch(Exception e){
			log.error("IPublicNeService getAllPublicNe error", e);
		}
		finally{
			JDBCTemplate.doSessionFinally();
		}
		
		return null;
	}

	public static void main(String[] args){
		try {
			System.out.println(CharliDate.getDayOfWeekOfTimeStamp("2011-3-1 13:00:00"));
		} 
		catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		List<DataAbnormal> unNormalRawDataLst=new ArrayList<DataAbnormal>();
		DataAbnormal ab=new DataAbnormal();
		ab.setAbnormalDesc("AA");
		ab.setAbnormalType("1");
		ab.setDatasetId("1111");
		ab.setDataTime(new Date());
		ab.setNeId("222");
		ab.setState("1");
		ab.setTimeStamp(new Date());
		unNormalRawDataLst.add(ab);
		
		ab=new DataAbnormal();
		ab.setAbnormalDesc("AAA");
		ab.setAbnormalType("1");
		ab.setDatasetId("2222");
		ab.setDataTime(new Date());
		ab.setNeId("111");
		ab.setState("1");
		ab.setTimeStamp(new Date());
		unNormalRawDataLst.add(ab);
		
		List<RawData> rawDataLst=new ArrayList<RawData>();
		RawData raw=new RawData();
		raw.setKpiId("111");
		raw.setNeId("111");
		raw.setDatasetId("111");
		raw.setIsNormal("1");
		raw.setCollectorDate((long)12348);
		raw.setTimeStamp(new Date());
		raw.setValidationType("1");
		raw.setValue(98.8);
		rawDataLst.add(raw);
		
		raw=new RawData();
		raw.setKpiId("222");
		raw.setNeId("222");
		raw.setDatasetId("222");
		raw.setIsNormal("1");
		raw.setCollectorDate((long)12348);
		raw.setTimeStamp(new Date());
		raw.setValidationType("1");
		raw.setValue(98.8);
		rawDataLst.add(raw);
		
		try{
			DataSourceFactory.initial();
			JDBCTemplate.jdbcBatchInsertObjects(rawDataLst, ModelInfo.rawDataOrMapping, true, true, JDBCTemplate.REQUIRES_NEW_COMMIT);
		}
		catch(Exception e){
			e.printStackTrace();
		}
		JDBCTemplate.doSessionFinally();
		
		IPublicNeService service=ServiceFactory.getInstance().getPublicNeService();
		List<Atom_PublicNe> results=service.getAllPublicNe();
		results.size();
		DataSourceFactory.getInstance().destory();
	}
	
}
